package com.xiaoran.client.cluster.impl;

import com.xiaoran.client.channel.ProviderService;
import com.xiaoran.client.cluster.ClusterStrategy;
import org.apache.commons.lang3.RandomUtils;

import javax.validation.constraints.Max;
import java.util.List;
import java.util.Random;
/**
 * 随机策略
 */
public class RandomClusterStrategyImpl implements ClusterStrategy {

    @Override
    public ProviderService select(List<ProviderService> serviceRoutes) {
        int size = serviceRoutes.size();
        int index = RandomUtils.nextInt(0, size - 1);
        return serviceRoutes.get(index);
    }
}
